package com.itheima.reggie.common;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class Result<T> {
    private Integer code;  // 1 成功， 0 和其他 失败
    private String msg;
    private T data;
    private Map map = new HashMap(); // 动态数据

    public static <T> Result<T> success(T data){
        Result<T> result = new Result<T>();
        result.data = data;
        result.code = 1;
        return result;
    }

    public static <T> Result<T> error(String msg){
        Result<T> result = new Result<T>();
        result.msg = msg;
        result.code = 0;
        return result;
    }

    public Result<T> add(String key,Object value){
        this.map.put(key,value);
        return this;
    }

}
